package cn.lastcrdg.testlrslide;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.blankj.utilcode.util.Utils;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private MyAdaptercopy mMyAdapter;
    private int status = 1; //0打开 1关闭
    private Button mBtn;
    private ArrayList<Bean> mList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Utils.init(getApplication());
        setContentView(R.layout.activity_main);
        RecyclerView recyclerView = findViewById(R.id.rv);
        mBtn = findViewById(R.id.btn);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addOnItemTouchListener(new SwipeItemLayout.OnSwipeItemTouchListener(this));
        mList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            Bean bean = new Bean();
            bean.setText("第" + (i+1) + "条数据");
            bean.setOpen(false);
            mList.add(bean);
        }
        mMyAdapter = new MyAdaptercopy(this, mList);
        recyclerView.setAdapter(mMyAdapter);
        mBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (status == 1) {
            mBtn.setText("完成");
            status = 0;
            for (int i = 0; i < mList.size(); i++) {
                mList.get(i).setOpen(true);
            }
            mMyAdapter.setDatas(mList);
        }else if (status == 0){
            mBtn.setText("编辑");
            status = 1;
            for (int i = 0; i < mList.size(); i++) {
                mList.get(i).setOpen(false);
            }
            mMyAdapter.setDatas(mList);
        }
    }
}
